home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / packer-tools / elzx / xpkelzx.c < prev    next >
C/C++ Source or Header  |  1996-03-12  |  6KB  |  279 lines

  1. /*
  2.  * This library is mainly intended to demonstrate how to program a sub
  3.  * library.
  4.  $VER: xpkELZX.c 1.0 (09/02/96) 
  5.  */
  6.  
  7. #define NO_SUB_PRAGMAS
  8. #define MaksymalnyC 0x60000
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <libraries/xpksub.h>
  13. #include <proto/dos.h>
  14. #include <proto/exec.h>
  15. #include <dos/dos.h>
  16. #include <dos/dostags.h>
  17. #include <exec/exec.h>
  18.  
  19. #define A3000 XPKMF_A3000SPEED
  20.  
  21. XMINFO RlenMode4 = {
  22.     NULL,        // next
  23.     100,         // upto
  24.     A3000,       // flags
  25.     0,           // packmem
  26.     0,           // unpackmem
  27.     30,         // packspeed,   K/sec
  28.     150,        // unpackspeed, K/sec
  29.     500,          // ratio,      *0.1%
  30.     0,           // reserved
  31.     "best"         // description
  32. };
  33. XMINFO RlenMode3 = {
  34.     &RlenMode4,  // next
  35.     80,         // upto
  36.     A3000,       // flags
  37.     0,           // packmem
  38.     0,           // unpackmem
  39.     31,         // packspeed,   K/sec
  40.     150,        // unpackspeed, K/sec
  41.     480,          // ratio,      *0.1%
  42.     0,           // reserved
  43.     "better"     // description
  44. };
  45. XMINFO RlenMode2 = {
  46.     &RlenMode3,  // next
  47.     60,         // upto
  48.     A3000,       // flags
  49.     0,           // packmem
  50.     0,           // unpackmem
  51.     32,         // packspeed,   K/sec
  52.     150,        // unpackspeed, K/sec
  53.     460,          // ratio,      *0.1%
  54.     0,           // reserved
  55.     "good"         // description
  56. };
  57. XMINFO RlenMode1 = {
  58.     &RlenMode2,  // next
  59.     40,         // upto
  60.     A3000,       // flags
  61.     0,           // packmem
  62.     0,           // unpackmem
  63.     33,         // packspeed,   K/sec
  64.     150,        // unpackspeed, K/sec
  65.     440,          // ratio,      *0.1%
  66.     0,           // reserved
  67.     "poor"         // description
  68. };
  69. XMINFO RlenMode = {
  70.     &RlenMode1,    // next
  71.     20,         // upto
  72.     A3000,       // flags
  73.     0,           // packmem
  74.     0,           // unpackmem
  75.     34,         // packspeed,   K/sec
  76.     150,        // unpackspeed, K/sec
  77.     10,          // ratio,      *0.1%
  78.     0,           // reserved
  79.     "none"         // description
  80. };
  81. #ifndef WERSJA_OKROJONA
  82. char *mody="012399";
  83. #else
  84. char *mody="012333";
  85. #endif
  86. static struct XpkInfo RlenInfo = {
  87.         1,               /* info version */
  88.         0,               /* lib  version */
  89.         0,               /* master vers  */
  90.         0,               /* pad          */
  91. #ifndef KOD_DELTA
  92.         "ELZX",          /* short name   */
  93.         "External LZX  ",/* long name    */
  94.         "very good compression library      middle speed   ", /* description*/
  95.         'ELZX',          /* 4 letter ID  */
  96. #else
  97.         "SLZX",          /* short name   */
  98.         "LZX with delta",/* long name    */
  99.         "External LZX compression for samples and mods     ", /* description*/
  100.         'SLZX',          /* 4 letter ID  */
  101. #endif
  102.         XPKIF_PK_CHUNK | /* flags        */
  103.         XPKIF_UP_CHUNK |
  104.         XPKIF_MODES,
  105.         MaksymalnyC,     /* max in chunk */
  106.         1,               /* min in chunk */
  107.         MaksymalnyC,     /* def in chunk */
  108.         NULL,            /* pk message   */
  109.         NULL,            /* up message   */
  110.         NULL,            /* pk past msg  */
  111.         NULL,            /* up past msg  */
  112.         80,              /* def mode     */
  113.         0,               /* pad          */
  114.         &RlenMode        /* modes        */
  115. };
  116.  
  117. /*
  118.  * Returns an info structure about our packer
  119.  */
  120. struct XpkInfo * __saveds __asm
  121. XpksPackerInfo( void )
  122. {
  123.     return &RlenInfo;
  124. }
  125.  
  126.  
  127. void __saveds __asm
  128. XpksPackFree( REG __a0 XPARAMS* xpar )
  129. {
  130. }
  131.  
  132. /*
  133.  * This forces the next chunk to be uncompressable independent from the
  134.  * previous one. This is always the case in RLEN.
  135.  */
  136. long __saveds __asm
  137. XpksPackReset( REG __a0 XPARAMS* xpar )
  138. {
  139.     return 0;
  140. }
  141.  
  142.  
  143. void __saveds __asm
  144. XpksUnpackFree( REG __a0 XPARAMS* xpar )
  145. {
  146. }
  147. /*
  148.  * Pack a chunk
  149.  */
  150. long __saveds __asm
  151. XpksPackChunk( REG __a0 XPARAMS *xpar )
  152. {
  153.     UBYTE *get =xpar->InBuf,*put=xpar->OutBuf;
  154. #ifdef KOD_DELTA
  155.     UBYTE *docel=xpar->OutBuf;
  156.     int   i;
  157. #endif
  158.  
  159. // Moje dodatki
  160.     char temp1[100],temp2[100],sysus[100];
  161.     struct Library *DOSBase;
  162.     struct ExecBase *ExecBase=(void *)4;
  163.     BPTR tmp; 
  164. #ifdef    Z_PIPE
  165.     BPTR we,wy;
  166. #endif
  167.     DOSBase=OpenLibrary("dos.library",37);
  168.     sprintf(temp1,"t:ltf%8x",ExecBase->ThisTask);
  169. #ifdef    Z_PIPE
  170.     sprintf(temp2,"pipe:ltf%8x.lzx",ExecBase->ThisTask);
  171. #else
  172.     sprintf(temp2,"t:ltf%8x.lzx",ExecBase->ThisTask);
  173. #endif
  174. #ifndef WERSJA_OKROJONA
  175.     sprintf(sysus,"lzx -Qf -%c af >nil: <nil: %s %s",mody[((xpar->Mode|1)-1)/20],temp2,temp1);
  176. #else
  177.     sprintf(sysus,"lzx -%c af >nil: <nil: %s %s",mody[((xpar->Mode|1)-1)/20],temp2,temp1);
  178. #endif
  179. #ifndef    Z_PIPE
  180.     DeleteFile(temp2);
  181. #endif
  182.     tmp=Open(temp1,MODE_NEWFILE);
  183. #ifdef     KOD_DELTA
  184.     for(i=0;docel<put+xpar->InLen;*docel++=*get-i,i=*get++) {};
  185.     Write(tmp,put,xpar->InLen);
  186. #else
  187.     Write(tmp,get,xpar->InLen);
  188. #endif
  189.     Close(tmp);
  190. #ifndef    Z_PIPE
  191.     SystemTagList(sysus,(void *)0);
  192.     tmp=Open(temp2,MODE_OLDFILE);
  193.     Seek(tmp,0,OFFSET_END);
  194.     if ( Seek(tmp,0,OFFSET_BEGINNING) < MaksymalnyC )
  195.         xpar->OutLen=Read(tmp,put,MaksymalnyC);
  196.      else
  197. #ifndef KOD_DELTA
  198.         CopyMem(get,put,xpar->OutLen=xpar->InLen);
  199. #else
  200.         xpar->OutLen=MaksymalnyC;
  201. #endif
  202. #else
  203.         we=Open("NIL:",MODE_READWRITE);
  204.         wy=Open("NIL:",MODE_READWRITE);
  205.         SystemTags(sysus,SYS_Asynch,1,SYS_Output,wy,SYS_Input,we,0);
  206.         tmp=Open(temp2,MODE_OLDFILE);
  207.         xpar->OutLen=Read(tmp,put,MaksymalnyC);
  208.         xpar->OutLen+=Read(tmp,put+xpar->OutLen,MaksymalnyC);
  209.         if ( xpar->OutLen==MaksymalnyC )
  210. #ifndef KOD_DELTA
  211.         CopyMem(get,put,xpar->OutLen=xpar->InLen);
  212. #else
  213.         {
  214.         xpar->OutLen=MaksymalnyC;
  215.         get=xpar->InBuf;
  216.         docel=put;
  217.         for(i=0;docel<put+xpar->InLen;*docel++=*get-i,i=*get++) {};
  218.         }
  219. #endif
  220. #endif
  221.     Close(tmp);
  222.     DeleteFile(temp1);
  223. #ifndef    Z_PIPE
  224.     DeleteFile(temp2);
  225. #endif
  226.     CloseLibrary(DOSBase);
  227.     return 0;
  228. }
  229.  
  230. long __saveds __asm
  231. XpksUnpackChunk( REG __a0 XPARAMS* xpar )
  232. {
  233.     char *get=xpar->InBuf, *put=xpar->OutBuf;
  234. #ifdef KOD_DELTA
  235.     int        x,i;
  236. #endif
  237.     char temp1[100],temp2[100],sysus[100];
  238.     struct Library *DOSBase;
  239. #ifndef    Z_PIPE
  240.     struct ExecBase *ExecBase=(void *)4;
  241. #endif
  242.     BPTR tmp;
  243.     if ( MaksymalnyC == xpar->InLen ) 
  244. #ifndef KOD_DELTA
  245.         CopyMem(get,put,MaksymalnyC);
  246. #else
  247.         for(x=0,i=MaksymalnyC;i--;*put+=x,x=*put++);
  248. #endif
  249.      else {
  250.         DOSBase=OpenLibrary("dos.library",37);
  251.         strcpy(temp1,"t:");
  252.         strncat(temp1,get+0x29,11);
  253. #ifdef Z_PIPE
  254.         sprintf(temp2,"mem:%d-%d",get,xpar->InLen);
  255. #else
  256.         sprintf(temp2,"t:ltf%8x.lzx",ExecBase->ThisTask);
  257.         tmp=Open(temp2,MODE_NEWFILE);
  258.         Write(tmp,get,xpar->InLen);
  259.         Close(tmp);
  260. #endif
  261.         sprintf(sysus,"lzx x >nil: <nil: %s t:",temp2);
  262.         SystemTagList(sysus,(void *)0);
  263.         tmp=Open(temp1,MODE_OLDFILE);
  264. #ifdef KOD_DELTA
  265.         i=Read(tmp,put,MaksymalnyC);
  266.         for(x=0;i--;*put+=x,x=*put++){};
  267. #else
  268.         Read(tmp,put,MaksymalnyC);
  269. #endif
  270.         Close(tmp);
  271.         DeleteFile(temp1);
  272. #ifndef Z_PIPE
  273.         DeleteFile(temp2);
  274. #endif
  275.         CloseLibrary(DOSBase);
  276.     }
  277.     return 0;
  278. }
  279.